package com.chengh.vhr.controller.system.basic;

import com.chengh.vhr.model.Department;
import com.chengh.vhr.model.RespBean;
import com.chengh.vhr.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理相关
 * @author chengh
 */
@RestController
@RequestMapping("/system/basic/Department")
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;

    /**
     * 找到所有的部门以及子部门
     * @return 所有的部门以及子部门
     */
    @GetMapping("/")
    public List<Department> getAllDepartments() {
        return departmentService.getAllDepartments();
    }

    @PostMapping("/")
    public RespBean addDepartment(@RequestBody Department department) {
        Integer departmentId = departmentService.addDepartment(department);
        if(departmentId != 0) {
            return RespBean.ok("添加部门成功!",departmentId);
        }
        return RespBean.error("添加部门失败!");
    }

    @DeleteMapping("/")
    public RespBean deleteDepartmentByIds(@RequestBody List<Integer> ids) {
        if(departmentService.deleteDepartmentByIds(ids)) {
            return RespBean.ok("删除部门成功!");
        }
        return RespBean.error("删除部门失败!请联系管理员!");
    }

}
